import java.io.File;
import java.io.IOException;

/**
 * Created by donar on 17/5/25.
 */
public class HtmlUtils {
    public static String htmlJsonTravel(String html,String field){
        int start = html.indexOf(field);
        if (start<0)return null;
        html=html.substring(start+field.length());
        if(!html.trim().startsWith(":")) return null;
        html=html.trim().substring(1).trim();
        if(!(html.startsWith("{")||html.startsWith("["))) return null;
        int bigBracketOpen=0;
        int bigBracketClose=0;
        int middleBracketOpen=0;
        int middleBracketClose=0;
        StringBuffer sb  = new StringBuffer();
        char[] chars = html.toCharArray();
        for (int i =0;i<chars.length;i++){
            if(chars[i]=='{') bigBracketOpen++;
            if(chars[i]=='}') bigBracketClose++;
            if(chars[i]=='[') middleBracketOpen++;
            if(chars[i]==']') middleBracketClose++;
            sb.append(chars[i]);
            if(bigBracketClose==bigBracketOpen&&middleBracketClose==middleBracketOpen) break;
        }
        return sb.toString();
    }
}
